//
//  AMPBaseViewController.swift
//  LivingHelper
//
//  Created by Ampaw on 2017/9/8.
//  Copyright © 2017年 Ampaw. All rights reserved.
//

import UIKit

class AMPBaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = AMPConstants.AMPBGViewColor
        setUpConfig()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.navigationItem.leftBarButtonItem = AMPCoreUtils.AMPBackBarButtonItem(#selector(backAction), taget: self)
    }
    
    // MARK: - Config
    /// 添加配置
    func setUpConfig(){
        // 指定边缘要延伸的方向，它的默认值很自然地是UIRectEdgeAll，四周边缘均延伸，就是说，如果即使视图中上有navigationBar，下有tabBar，那么视图仍会延伸覆盖到四周的区域
        self.edgesForExtendedLayout = UIRectEdge()
        // 默认值为NO(看有些文章说默认值是YES,不知道是不是XCode7之后苹果修改了这个值，以前到没怎么在意),这个属性在状态栏不透明的状态下才生效。也就是说，一般使用这个属性应该这样使用：
        // YES：视图延伸不考虑透明的Bars(这里包含导航栏和状态栏)  NO：意思就是空出导航栏位置
        self.extendedLayoutIncludesOpaqueBars = false
        // 隐藏状态栏的功能,false 为不隐藏
        self.modalPresentationCapturesStatusBarAppearance = false
        // 当 automaticallyAdjustsScrollViewInsets 为 NO 时，tableview 是从屏幕的最上边开始，也就是被导航栏 & 状态栏覆盖; 当 automaticallyAdjustsScrollViewInsets 为 YES 时，也是默认行为,表现就比较正常
        self.automaticallyAdjustsScrollViewInsets = true
    }
    
    // MARK: - Event
    func backAction() {
        navigationController!.popViewController(animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
